<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:composite="http://java.sun.com/jsf/composite">
     
	<composite:interface>
		<composite:attribute name="id"/>
		<composite:attribute name="controller" required="true"/>
		<composite:attribute name="title" required="true"/>			
	</composite:interface>

	<composite:implementation>		
		<ui:decorate template="/pages/template/template.xhtml">			
			<ui:define name="dynamic_content">   
				<h:body>
					<p:messages id="messages" showDetail="true" autoUpdate="true"  closable="true" globalOnly="true" />	
						<h:form id="form" prependId="false">
							
							<p:toolbar id="toolbar" >  
								<p:toolbarGroup align="left">
									<p:commandButton id="novo" value="#{bundle['app.label.new']}" icon="ui-icon-document" actionListener="#{cc.attrs.controller.create}" update="@form"  disabled="#{!cc.attrs.controller.btnNovoVisivel}" process="@this"/>														     
									<p:commandButton id="editar" value="#{bundle['app.label.edit']}" icon="ui-icon-circle-plus" actionListener="#{cc.attrs.controller.edit}" update="@form" disabled="#{!cc.attrs.controller.btnEditarVisivel}" process="@this"/>
									<p:commandButton id="deletar" value="#{bundle['app.label.delete']}" title="Delete" icon="ui-icon-trash"  update="panelConfirmDialog" onclick="excluir.show()" disabled="#{!cc.attrs.controller.btnDeletarVisivel}"/>
									<p:commandButton id="selecionar" value="#{bundle['app.label.selecionarCampos']}" title="Selecionar Campos" onclick="pickList.show()" disabled="#{!cc.attrs.controller.btnSelecionarCamposVisivel}"/>					   
								</p:toolbarGroup> 
							</p:toolbar>  		
										
							<p:dataTable id="grid-registro"			
								var="registro" 
								value="#{cc.attrs.controller.listaEntidades}" 
								rendered="#{cc.attrs.controller.controllerGrid}" 
								selection="#{cc.attrs.controller.entidadeSelecionada}" 
								rowKey="#{registro.id}">
												
								<p:ajax event="rowSelectCheckbox"  listener="#{cc.attrs.controller.controllerButton}"  update=":#{cc.clientId}:form:toolbar"/>
												
								<p:ajax event="rowUnselectCheckbox"  listener="#{cc.attrs.controller.controllerButton}"  update=":#{cc.clientId}:form:toolbar"/>
											
								<p:ajax event="toggleSelect"  listener="#{cc.attrs.controller.controllerButton}"  update=":#{cc.clientId}:form:toolbar"/>
													
								<p:column selectionMode="multiple" styleClass="coluna-grid-center"/>  
												
								<p:columns value="#{cc.attrs.controller.colunas}" var="colunas" sortBy="#{registro[colunas.property]}" filterBy="#{registro[colunas.property]}" filterMatchMode="contains"> 
												 
									<f:facet name="header">  
										#{grid[colunas.header]}
									</f:facet>			
										
									#{registro[colunas.property]}
										
								</p:columns>  	
																							 
							</p:dataTable>
										
							
							<p:dialog id="pick-list-colunas" header="#{cc.attrs.title}" widgetVar="pickList" resizable="false"> 
								
								<p:pickList id="pojoPickList"
									value="#{cc.attrs.controller.pickListGrid}"
									var="pickListGrid"
									converter="entityConverter"
									itemValue="#{pickListGrid}" 
									itemLabel="#{grid[pickListGrid.nomeColuna]}"  
									showSourceControls="true" 
									showTargetControls="false"
									showCheckbox="true"  
									showSourceFilter="true"
									showTargetFilter="true" 
									filterMatchMode="contains">
																		  
									<f:facet name="sourceCaption">#{bundle['app.label.exibirColunas']}</f:facet>  
							        
									<f:facet name="targetCaption">#{bundle['app.label.ocultarColunas']}</f:facet>
							        	
								</p:pickList>  
								  	
								<p:commandButton id="salvarPickList" value="#{bundle['app.label.save']}"  actionListener="#{cc.attrs.controller.saveColumns()}"  update="pojoPickList, :#{cc.clientId}:form:grid-registro" /> 
									
								<p:commandButton id="fecharPickList" value="#{bundle['app.label.fechar']}"  onclick="pickList.hide()"/>
															  
							</p:dialog>
														 
							<p:dialog id="confirmDialog" header="#{bundle['app.label.delete']}" widgetVar="excluir" resizable="false" modal="true" height="150" width="300"> 
								<p:scrollPanel id="panelConfirmDialog" style="height:120px" scrollMode="native">  
									<p:dataList value="#{cc.attrs.controller.entidadeSelecionada}" var="entidade" type="ordered">  
										<p:outputLabel value="#{entidade.nome}"/>					  
									</p:dataList>  			  		
								</p:scrollPanel>
							 
								<div align="center" > 
									<p:commandButton id="sim" value="#{bundle['app.label.yes']}"  update="@form" oncomplete="excluir.hide()" actionListener="#{cc.attrs.controller.delete}"/>  
									<p:commandButton id="nao" value="#{bundle['app.label.no']}" onclick="excluir.hide()"/>
								</div>                
							</p:dialog>  
							  
							<div align="center"  class="container-top">		
								<p:panel id="cadastro" header="#{cc.attrs.title}" styleClass="panel_fullscreen" rendered="#{cc.attrs.controller.controllerCadastro}">									
									<composite:insertChildren>
										<!-- Tudo que for colocado dentro das tag do controllerView vai aparecer aqui -->
									</composite:insertChildren>
										
									<h:panelGrid border="0" columns="3" styleClass="container-top" >
										<p:commandButton id="salvarForm" value="#{bundle['app.label.save']}" action="#{cc.attrs.controller.save}" update="@form"/>
										<p:commandButton id="limparForm" type="reset" value="#{bundle['app.label.clean']}" /> 
										<p:commandButton id="fecharForm" value="#{bundle['app.label.fechar']}" action="#{cc.attrs.controller.controllerButtonClean}" actionListener="#{cc.attrs.controller.close}" update="@form" process="@this">  
											<p:resetInput target="form" />  
										</p:commandButton> 				
									</h:panelGrid>
								</p:panel>
							</div>
							
							<p:remoteCommand name="update" update="@form"/>  
						  	  
						</h:form>  
					</h:body>
				</ui:define>
		</ui:decorate>
	</composite:implementation>
      
</html>